package com.itheima.controller;

import com.itheima.admin.orderpojo.Order;
import com.itheima.common.JsonResult;
import com.itheima.admin.AdminPage;
import com.itheima.admin.orderpojo.vo.OrderQueryVo;
import com.itheima.admin.orderpojo.vo.OrderStatusVo;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuzhiyong
 */
@RestController
@RequestMapping(value = "/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 分页
     *
     * @param orderQueryVo orderQueryVo
     * @return JsonResult
     */
    @GetMapping(value = "/page")
    public JsonResult<AdminPage<Order>> orderPage(OrderQueryVo orderQueryVo) {
        AdminPage<Order> adminPage = orderService.getpageOrder(orderQueryVo);
        if (adminPage != null) {
            return JsonResult.success(adminPage, null);
        }
        return JsonResult.error(null);
    }
    /**
     * 修改状态
     * @param orderStatusVo orderStatusVo
     * @return true false
     */
    @PutMapping
    public JsonResult<Object> orderStatus(@RequestBody OrderStatusVo orderStatusVo) {
        return orderService.modifyStatusById(orderStatusVo) ? JsonResult.success("成功", null) : JsonResult.error("失败");
    }
}
